/*
 * EventUser.h
 *
 *  Created on: Jun 2, 2010
 *      Author: sdaniele
 */

#ifndef EVENTUSER_H_
#define EVENTUSER_H_

#define nocopy(c)\
private:\
	c(c&);

#include "tbb/spin_mutex.h"
#include "systemc.h"
#include <string>
#include <iostream>

namespace noti {


typedef ::tbb::spin_mutex mutex_t;

/**
 * Base class for all event user types, abstract
 *
 */
class EventUser : public sc_module{
	nocopy(EventUser);
protected:
	sc_event* m_event;
	sc_in<bool> m_clk;
	::std::string m_name;
	bool m_is_thread;

protected:
	virtual void before_end_of_elaboration(){
		if(m_is_thread){ SC_THREAD(do_thread_work); }
		else 		 { SC_METHOD(do_method_work); }
		init_sensitive();
		dont_initialize();
	}
	virtual void init_sensitive()=0;
	virtual ::std::string report() const;

public:
	SC_HAS_PROCESS(EventUser);
	EventUser(sc_module_name name, sc_event* event, const sc_clock* clk, bool is_thread );

	virtual ~EventUser()=0;

	virtual void do_thread_work();
	virtual void do_method_work();

	void print_report() const;

private:
	 static mutex_t mu_cout;		//mutex to prevent printout garbling
};


}
#endif /* EVENTUSER_H_ */
